package com.hanyi.mvc.contorller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class ForwardContorller {
    @RequestMapping("/default")
    public String defaultForward(){
        System.out.println("默认转发方式");
        return "success"; // 视图解析器拼接前后缀
    }

    @RequestMapping("/forward")
    public String forward(){
        System.out.println("forward转发方式");
        return "forward:/WEB-INF/pages/success.jsp"; // 视图解析器不拼接前后缀,不在视图解析器前后缀路径是使用
    }
    @RequestMapping("API")
    public void API(HttpServletRequest request, HttpServletResponse response){
        System.out.println("原生api实现");
        try {
            request.getRequestDispatcher("/WEB-INF/pages/success.jsp").forward(request,response);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
